﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 垃圾小游戏.class1;
using 垃圾小游戏.class3;
using 垃圾小游戏.class6;

namespace 垃圾小游戏.class4
{
    class Food : GameObject
    {
        public Food(Snake snake)
        {
            RandomPos(snake);
        }

        public override void Draw()
        {
            Console.SetCursorPosition(pos.x,pos.y);
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("⊕");
        }
        public void RandomPos(Snake snake)
        {
            //随机位置
            Random r = new Random();
            //食物位置不能与蛇和墙的位置重合
            int x = r.Next(2,Game.w / 2 - 1) * 2;
            int y = r.Next(1,Game.h - 4);
            pos = new Position(x,y);
            //得到蛇
            //如果重合，进if语句重新生成
            if(snake.CheckSamPos(pos))
            {
                RandomPos(snake);//递归
            }
        }
    }
}
